Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • question about the operator "or" ( | )

    Sorry about this simple question, but it would be great to get some verification.
    I try to define first generation immigrants as someone foreign born (let's say India) with at least one Indian parent. So I write:

    Code:
     gen indian = 1 if bornIndia==1 & (momIndian==1 | dadIndian==1)
    My question is about the operator |. So far, I assume that the above means that either mom is Indian or dad is Indian or BOTH are Indian.

    I am uncertain about the BOTH.

    Is this implied with the operator | ? I am pretty sure it is.

    Thanks a lot!

    Best wishes.

    Nico



  • #2

    So make a small example to check:
    Code:
    . input float(bornIndia momIndian dadIndian)
    
         bornIndia  momIndian  dadIndian
      1. 1 1 0
      2. 1 0 1
      3. 1 1 1
      4. 1 0 0
      5. end
    
    . 
    . gen indian = 1 if bornIndia==1 & (momIndian==1 | dadIndian==1)
    (1 missing value generated)
    
    . 
    . list
    
         +-----------------------------------------+
         | bornIn~a   momInd~n   dadInd~n   indian |
         |-----------------------------------------|
      1. |        1          1          0        1 |
      2. |        1          0          1        1 |
      3. |        1          1          1        1 |
      4. |        1          0          0        . |
         +-----------------------------------------+
    
    .
    Answer, yes, your understanding is correct

    Comment


    • #3
      Thank you very much Jorrit. Very nice example indeed. It got me thinking about my definition of first generation immigrants. May be I should just define Indians as born in India without any restrictions. I will think about that some more. In the meantime, have a great day!!!!

      Comment

      Working...
      X